package elec;

import tennos.Lump;
import static java.lang.Math.*;
import static mathUtils.VecMath.*;
import processing.core.*;

public class ElectroLump extends Lump implements Electric {

	public float charge;
	public float radius;
		
	public ElectroLump(PApplet p, float c, float r, float px, float py) {
		super(p, px, py);
		charge = c;
		radius = r;
	}
	
	public static int electricDimension = 3;
	
	public float charge() {return charge;}
	public float electricRho() {return radius;}

	public float[] eFieldAt(float x[], float bigK) {
		float e[] = x.clone();
		vecSub(e, position(), e);
		float r = vecMag(e);
		float scaleFac = (float) pow(1f/max(r, radius), electricDimension);
		vecScale(e, bigK*charge()*scaleFac);
		return e;
	}
	public float[] eFieldAt(float x[]) {return eFieldAt(x, 1.0f);}
	
	public float[] eForceOn(Electric a, float bigK) {
		float f[];
		f = eFieldAt(a.position());
		vecScale(f, a.charge());
		return f;
	}
	
	public void draw() {
		parent.stroke(250f*0.5f*(1+signum(charge)), 250f*0.5f*(1-signum(charge)), 0f);
		parent.strokeWeight(0);
		parent.fill(250f*0.5f*(1+signum(charge)), 250f*0.5f*(1-signum(charge)), 0f);
		parent.ellipse(position()[0], position()[1], radius/2, radius/2);
	}
}
